package com.syqc.monitor.ui.cost

import com.syqc.comlib.utils.GsonUtil
import com.syqc.entity.OtherInfoFee
import com.syqc.monitor.R
import com.syqc.utils.TimeUtil

class OtherViewModel : BaseFeeViewModel() {

    var feeOther = ""
    private var otherFeeEntity: String = ""
    private var otherFee: String = ""

    //加油日期
    var update = TimeUtil.instance.getNowTime(true)

    override fun isParamsOk(): Boolean {
        if (carId.isEmpty()) {
            toast(R.string.hint_toast_choose_car)
            return false
        }
        if (feeOther.isEmpty()) {
            toast(R.string.hint_toast_fee)
            return false
        }

        val entity = OtherInfoFee(
            carId, update, remark, feeOther
        )

        otherFee = GsonUtil.toJson(entity)
        if ("$otherFee$photos" == otherFeeEntity && isSuccess) {
            toast(R.string.toast_repeat_same_data)
            return false
        }
        otherFeeEntity = "$otherFee$photos"
        return true
    }

    fun uploadOther() {
        if (!isParamsOk()) return
        uploadFee("FeeOther", otherFee.replace("%","%25"))
    }

    override fun clearData() {
        super.clearData()
        update = TimeUtil.instance.getNowTime(true)
    }
}